﻿using VoxelBlock.VoxelBlock3D;
using System.Collections.Generic;
using UnityEngine;

public class DrawVoxel3DCoreComponent : MonoBehaviour
{
    private DrawVoxel3DCoreManager drawVoxel3DCoreManager;

    private OperateCreate3D operateCreate3D;

    private DrawVoxel3DCore drawVoxel3DCore;

    public Material mainMaterial;

    float alpha = 1;
    public float Alpha
    {
        get
        {
            return alpha;
        }

        set
        {
            if (mainMaterial)
            {
                mainMaterial.SetColor("_Color", new Color(1, 1, 1, value));
            }
            alpha = value;
        }
    }

    public DrawVoxel3DCore mainDrawVoxel3DCore
    {
        get
        {
            return drawVoxel3DCore;
        }

        set
        {
            drawVoxel3DCore = value;
            mainMaterial = drawVoxel3DCore.mainMaterial;
        }
    }

    public void MyStart(DrawVoxel3DCore drawVoxel3DCore, OperateCreate3D operateCreate3D, DrawVoxel3DCoreManager drawVoxel3DCoreManager)
    {
        this.mainDrawVoxel3DCore = drawVoxel3DCore;
        this.operateCreate3D = operateCreate3D;
        this.gameObject.AddComponent<UnitMeshPointComponent>();
        this.drawVoxel3DCoreManager = drawVoxel3DCoreManager;
    }

    public void MyStart(DrawVoxel3DCore drawVoxel3DCore, OperateCreate3D operateCreate3D, Transform boneTarget, DrawVoxel3DCoreManager drawVoxel3DCoreManager)
    {
        this.mainDrawVoxel3DCore = drawVoxel3DCore;
        this.operateCreate3D = operateCreate3D;
        this.gameObject.AddComponent<UnitMeshPointComponent>().m_boneTarget = boneTarget;
        this.drawVoxel3DCoreManager = drawVoxel3DCoreManager;
    }

    public void Delete()
    {
        drawVoxel3DCoreManager.Remove(drawVoxel3DCore);
        //drawVoxel3DCore.Clear();
        //Destroy(this.gameObject);
    }

    public bool Merge()
    {
        if (operateCreate3D.Merge(mainDrawVoxel3DCore))
        {
            Delete();
            return true;
        }
        return false;
    }

    public void EsitorChange()
    {
        operateCreate3D.EsitorChange(mainDrawVoxel3DCore);
    }
    
}

